package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;
import org.xx.armory.objectparser.ParsedObject;
import org.xx.armory.swing.components.TypedTableColumnType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import static org.xx.armory.commons.Validators.notBlank;
import static org.xx.armory.commons.Validators.notNull;

public class TableColumnModel
        extends ParsedObject {
    private final String name;
    private final String title;
    private final TypedTableColumnType type;
    private final int size;
    private final String optionsName;
    private final List<OptionModel> options;

    /**
     * 构造解析对象。
     *
     * @param lineInfo
     *         源文件中的位置信息。
     */
    protected TableColumnModel(
            LineInfo lineInfo,
            String name,
            String title,
            TypedTableColumnType type,
            int size,
            String optionsName,
            Collection<? extends OptionModel> options
    ) {
        super(lineInfo);

        this.name = notBlank(name, "name").trim();
        this.title = trimToEmpty(title);
        this.type = notNull(type, "type");
        this.size = size;
        this.optionsName = trimToEmpty(optionsName);
        this.options = options != null ? new ArrayList<>(options) : Collections.emptyList();
    }

    public String getName() {
        return this.name;
    }

    public String getTitle() {
        return this.title;
    }

    public TypedTableColumnType getType() {
        return this.type;
    }

    public int getSize() {
        return this.size;
    }

    public String getOptionsName() {
        return this.optionsName;
    }

    public List<OptionModel> getOptions() {
        return this.options;
    }
}
